package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.*;
import com.googlecode.gwtbb.client.shared.validation.FieldId;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public abstract class LabeledFormEntry extends FormEntryImpl implements HasHorizontalAlignment, HasVerticalAlignment {
	private Label label;
	private int labelRow = 0;
	private int labelCol = 0;
	private int labelRowSpan = 1;
	private int labelColSpan = 1;
	private HorizontalAlignmentConstant labelHorizontalAlignment = ALIGN_LEFT;
	private VerticalAlignmentConstant labelVerticalAlignment = ALIGN_MIDDLE;
	private int entryRow = 0;
	private int entryCol = 1;
	private int entryRowSpan = 1;
	private int entryColSpan = 1;
	private HorizontalAlignmentConstant entryHorizontalAlignment = ALIGN_LEFT;
	private VerticalAlignmentConstant entryVerticalAlignment = ALIGN_MIDDLE;
	private List<WidgetCell> widgetCells;

	public LabeledFormEntry(FieldId fieldId, String defaultValue, int labelRow, int labelCol, String labelText) {
		this.fieldId = fieldId;
		this.defaultValue = defaultValue;
		label = new Label(labelText);
		this.labelRow = labelRow;
		this.labelCol = labelCol;
		this.entryRow = labelRow;
		this.entryCol = labelCol + 1;
	}

	public int getEntryCol() {
		return entryCol;
	}

	public void setEntryCol(int entryCol) {
		this.entryCol = entryCol;
	}

	public int getEntryColSpan() {
		return entryColSpan;
	}

	public void setEntryColSpan(int entryColSpan) {
		this.entryColSpan = entryColSpan;
	}

	public HorizontalAlignmentConstant getEntryHorizontalAlignment() {
		return entryHorizontalAlignment;
	}

	public void setEntryHorizontalAlignment(HorizontalAlignmentConstant entryHorizontalAlignment) {
		this.entryHorizontalAlignment = entryHorizontalAlignment;
	}

	public int getEntryRow() {
		return entryRow;
	}

	public void setEntryRow(int entryRow) {
		this.entryRow = entryRow;
	}

	public int getEntryRowSpan() {
		return entryRowSpan;
	}

	public void setEntryRowSpan(int entryRowSpan) {
		this.entryRowSpan = entryRowSpan;
	}

	public VerticalAlignmentConstant getEntryVerticalAlignment() {
		return entryVerticalAlignment;
	}

	public void setEntryVerticalAlignment(VerticalAlignmentConstant entryVerticalAlignment) {
		this.entryVerticalAlignment = entryVerticalAlignment;
	}

	public Label getLabel() {
		return label;
	}

	public void setLabel(Label label) {
		this.label = label;
	}

	public int getLabelCol() {
		return labelCol;
	}

	public void setLabelCol(int labelCol) {
		this.labelCol = labelCol;
	}

	public int getLabelColSpan() {
		return labelColSpan;
	}

	public void setLabelColSpan(int labelColSpan) {
		this.labelColSpan = labelColSpan;
	}

	public HorizontalAlignmentConstant getLabelHorizontalAlignment() {
		return labelHorizontalAlignment;
	}

	public void setLabelHorizontalAlignment(HorizontalAlignmentConstant labelHorizontalAlignment) {
		this.labelHorizontalAlignment = labelHorizontalAlignment;
	}

	public int getLabelRow() {
		return labelRow;
	}

	public void setLabelRow(int labelRow) {
		this.labelRow = labelRow;
	}

	public int getLabelRowSpan() {
		return labelRowSpan;
	}

	public void setLabelRowSpan(int labelRowSpan) {
		this.labelRowSpan = labelRowSpan;
	}

	public VerticalAlignmentConstant getLabelVerticalAlignment() {
		return labelVerticalAlignment;
	}

	public void setLabelVerticalAlignment(VerticalAlignmentConstant labelVerticalAlignment) {
		this.labelVerticalAlignment = labelVerticalAlignment;
	}

	public List<WidgetCell> getWidgetCells() {
		if (widgetCells == null) {
			widgetCells = new ArrayList<WidgetCell>(2);
			Panel labelCell = new VerticalPanel();
			labelCell.add(getFailurePanel());
			labelCell.add(label);
			widgetCells.add(new WidgetCell(labelCell, labelRow, labelCol, labelRowSpan, labelColSpan, labelHorizontalAlignment, labelVerticalAlignment));
			widgetCells.add(new WidgetCell(getEntryWidget(), entryRow, entryCol, entryRowSpan, entryColSpan, entryHorizontalAlignment, entryVerticalAlignment));
		}
		return widgetCells;
	}

	public HorizontalAlignmentConstant getHorizontalAlignment() {
		throw new UnsupportedOperationException("use getLabelHorizontalAlignment or getEntryHorizontalAlignment");
	}

	public VerticalAlignmentConstant getVerticalAlignment() {
		throw new UnsupportedOperationException("use getLabelVerticalAlignment or getEntryVerticalAlignment");
	}

	public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
		throw new UnsupportedOperationException("use setLabelHorizontalAlignment or setEntryHorizontalAlignment");
	}

	public void setVerticalAlignment(VerticalAlignmentConstant align) {
		throw new UnsupportedOperationException("use setLabelVerticalAlignment or setEntryVerticalAlignment");
	}
}
